import Vue from 'vue'
import VueRouter from 'vue-router'

const Login = () => import(/* webpackChunkName: "login" */'../components/Login.vue')
const Home = () => import(/* webpackChunkName: "home" */'../components/Home.vue')
const Index = () => import(/* webpackChunkName: "home" */'../components/index/Index.vue')
const PersonalCenter = () => import(/* webpackChunkName: "home" */'../components/PersonalCenter.vue')
const Document = () => import(/* webpackChunkName: "document" */'../components/document/Document.vue')
const Guide = () => import(/* webpackChunkName: "guide" */'../components/guide/Guide.vue')
const SetPower = () => import(/* webpackChunkName: "power" */'../components/power/SetPower.vue')
const No404 = () => import(/* webpackChunkName: "error" */'../views/No404.vue')
const Directive = () => import(/* webpackChunkName: "power" */'../components/power/Directive.vue')
const Role = () => import(/* webpackChunkName: "power" */'../components/power/Role.vue')
const Icon = () => import(/* webpackChunkName: "icon" */'../components/icon/Icon.vue')
const Editor = () => import(/* webpackChunkName: "components" */'../components/components/Editor.vue')
const Markdown = () => import(/* webpackChunkName: "components" */'../components/components/Markdown.vue')
const SplitPane = () => import(/* webpackChunkName: "components" */'../components/components/SplitPane.vue')
const UploadHead = () => import(/* webpackChunkName: "components1" */'../components/components/Upload-head.vue')
const Sortablejs = () => import(/* webpackChunkName: "components1" */'../components/components/Sortablejs.vue')
const KeyEcharts = () => import(/* webpackChunkName: "echarts" */'../components/echarts/KeyEcharts.vue')
const LineEcharts = () => import(/* webpackChunkName: "echarts" */'../components/echarts/LineEcharts.vue')
const Mick = () => import(/* webpackChunkName: "echarts" */'../components/echarts/Mick.vue')
const DyncTable = () => import(/* webpackChunkName: "table" */'../components/table/DyncTable.vue')
const DrapTable = () => import(/* webpackChunkName: "table" */'../components/table/DrapTable.vue')
const EditTable = () => import(/* webpackChunkName: "table" */'../components/table/EditTable.vue')
const ComprehensiveTable = () => import(/* webpackChunkName: "table" */'../components/table/ComprehensiveTable.vue')
const CreateArticle = () => import(/* webpackChunkName: "article" */'../components/article/CreateArticle.vue')
const ArticleList = () => import(/* webpackChunkName: "article" */'../components/article/ArticleList.vue')
const Pre = () => import(/* webpackChunkName: "pre" */'../views/reloadPre.vue')
const Tab = () => import(/* webpackChunkName: "tab" */'../components/tab/Tab.vue')
const Error401 = () => import(/* webpackChunkName: "error" */'../components/error/Error401.vue')
const ExcelOut = () => import(/* webpackChunkName: "excel1" */'../components/excel/ExcelOut.vue')
const OutputSelect = () => import(/* webpackChunkName: "excel1" */'../components/excel/OutputSelect.vue')
const MoreTableHead = () => import(/* webpackChunkName: "excel1" */'../components/excel/MoreTableHead.vue')
const UploadExcel = () => import(/* webpackChunkName: "excel1" */'../components/excel/UploadExcel.vue')
const Zip = () => import(/* webpackChunkName: "excel1" */'../components/zip/Zip.vue')
const PDF = () => import(/* webpackChunkName: "excel2" */'../components/pdf/PDF.vue')
const Filter = () => import(/* webpackChunkName: "excel" */'../components/filter/Filter.vue')
const I18n = () => import(/* webpackChunkName: "more" */'../components/i18n/I18n.vue')
const Plugins = () => import(/* webpackChunkName: "more" */'../components/plugin/Plugins.vue')

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  {
    path: '/home',
    component: Home,
    redirect: '/indexPage',
    name: 'home',
    children: [
      { path: '/indexPage', component: Index },
      { path: '/document', component: Document },
      { path: '/personalCenter', component: PersonalCenter },
      { path: '/guide', component: Guide },
      { path: '/permission/power', component: SetPower },
      { path: '/permission/directive', component: Directive },
      { path: '/permission/role', component: Role },
      { path: '/icons', component: Icon },
      { path: '/components/editor', component: Editor },
      { path: '/components/markdown', component: Markdown },
      { path: '/components/splitpane', component: SplitPane },
      { path: '/components/upload-head', component: UploadHead },
      { path: '/components/Sortablejs', component: Sortablejs },
      { path: '/echarts/key', component: KeyEcharts },
      { path: '/echarts/line', component: LineEcharts },
      { path: '/echarts/mick', component: Mick },
      { path: '/routers/dynctable', component: DyncTable },
      { path: '/routers/draptable', component: DrapTable },
      { path: '/routers/edit', component: EditTable },
      { path: '/routers/mick', component: ComprehensiveTable },
      { path: '/caselist/createarticle', name: 'editArticle', component: CreateArticle },
      { path: '/caselist/list', name: 'list', component: ArticleList },
      { path: '/pre', name: 'pre', component: Pre },
      { path: '/tab', component: Tab },
      { path: '/errors/404', component: No404 },
      { path: '/errors/401', component: Error401 },
      { path: '/excel/out', component: ExcelOut },
      { path: '/excel/outitem', component: OutputSelect },
      { path: '/excel/outmany', component: MoreTableHead },
      { path: '/excel/uploadexcel', component: UploadExcel },
      { path: '/zip/export', component: Zip },
      { path: '/pdf', component: PDF },
      { path: '/filter', component: Filter },
      { path: '/internal', component: I18n },
      { path: '/plugins', component: Plugins }
    ]
  },
  { path: '/404', component: No404 },
  { path: '*', component: No404 }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if(to.path === '/login') return next()
  if(window.sessionStorage.getItem('token') !== 'isTrue') return next('/login')
  next()
})
export default router
